﻿using Microsoft.AspNetCore.Mvc;
using Shop.Core.Share;
using Shop.IServices.Admin;
using Shop.Model.Dto.Admin.Goods;
using Shop.Model.View.Admin.Goods;

namespace Shop.AdminApi.Controllers;

/// <summary>
/// 商品管理服务
/// </summary>
[ApiController]
[Route("admin/[controller]")]
public class GoodsController: ShopControllerBase
{
    private readonly IGoodsService _godService;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="godService"></param>
    public GoodsController(IGoodsService godService)
    {
        _godService = godService;
    }
    
    /// <summary>
    /// 商品列表
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpGet("GodList")]
    public AppResult<PageModel<GodListVo>> GodList([FromQuery] GodListDto dto)
        => _godService.GodList(dto);

    /// <summary>
    /// 商品状态(常量)
    /// </summary>
    /// <returns></returns>
    [HttpGet("GodState")]
    public AppResult<List<GodStateVo>> GodState()
    {
        var godStateVo = new List<GodStateVo>();
        var godStateOne = new GodStateVo() { Key = 1, Value = "上架", Sort = 0 };
        var godStateTwo = new GodStateVo() { Key = 2, Value = "下架", Sort = 1 };
        var godStateThree = new GodStateVo() { Key = 3, Value = "删除", Sort = 2 };
        godStateVo.Add(godStateOne);
        godStateVo.Add(godStateTwo);
        godStateVo.Add(godStateThree);
        return godStateVo;
    }
    
    /// <summary>
    /// 商品类型(常量)
    /// </summary>
    /// <returns></returns>
    [HttpGet("GodType")]
    public AppResult<List<GodStateVo>> GodType()
    {
        var godStateVo = new List<GodStateVo>();
        var godStateOne = new GodStateVo() { Key = 1, Value = "单品", Sort = 0 };
        var godStateTwo = new GodStateVo() { Key = 2, Value = "礼包", Sort = 1 };
        godStateVo.Add(godStateOne);
        godStateVo.Add(godStateTwo);
        return godStateVo;
    }
    

    /// <summary>
    /// 新增商品
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("GodAdd")]
    public AppResult GodAdd(GodAddDto dto)
        => _godService.GodAdd(dto);

    /// <summary>
    /// 商品详情
    /// </summary>
    /// <param name="gId"></param>
    /// <returns></returns>
    [HttpGet("GodDetails")]
    public AppResult<GodDetailsVo> GodDetails([FromQuery] long gId)
        => _godService.GodDetails(gId);

    /// <summary>
    /// 修改商品
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost("GodEdit")]
    public AppResult GodEdit(GodEditDto dto)
        => _godService.GodEdit(dto);

    /// <summary>
    /// 删除商品
    /// </summary>
    /// <param name="gId"></param>
    /// <returns></returns>
    [HttpPost("GodDel")]
    public AppResult GodDel(List<long> gId)
        => _godService.GodDel(gId);

    /// <summary>
    /// 下架商品
    /// </summary>
    /// <param name="gId"></param>
    /// <returns></returns>
    [HttpPost("GodOut")]
    public AppResult GodOut(List<long> gId)
        => _godService.GodOut(gId);
    
    /// <summary>
    /// 上架商品
    /// </summary>
    /// <param name="gId"></param>
    /// <returns></returns>
    [HttpPost("GodUp")]
    public AppResult GodUp(List<long> gId)
        => _godService.GodUp(gId);
}